package queue;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * Created by brossdong on 2018/1/19.
 * 带有排序的queue
 * 只有当take的时候才会比较
 * 必须实现Comparable接口
 */
public class UsePriorityQueue {

    public static void main(String[] args) throws Exception{

        PriorityBlockingQueue<Task> q = new PriorityBlockingQueue<Task>();

        Task t1 = new Task();
        t1.setId(3);
        t1.setName("任务1");
        q.add(t1);

        Task t2 = new Task();
        t2.setId(6);
        t2.setName("任务2");
        q.add(t2);

        Task t3 = new Task();
        t3.setId(1);
        t3.setName("任务3");
        q.add(t3);

        System.out.println("容器:" + q);
        System.out.println(q.take().getId());
        System.out.println("容器:" + q);
    }

}
